import 'package:flutter/material.dart';
import '../../common/style/style.dart' show AppColors, Constants, ICons;
import '../../model/conversation.dart';

class ConversationItem extends StatelessWidget {
  ConversationItem(this.conversationItemData, this.index, this.type,
      this.selected, this.onPress)
      : assert(conversationItemData != null);
  int index;
  int type;

  final Conversation conversationItemData;
  final Function(Conversation item, int index)? onPress;
  bool selected = false;
  var tapPos;
  @override
  Widget build(BuildContext context) {
    //print("build item " + index.toString());

    return Material(
      color: Color(AppColors.ConversationItemBg),
      child: InkWell(
        onTap: () {
          print('打开会话:${conversationItemData.title}');

          this.onPress?.call(conversationItemData, index);
        },
        onTapDown: (TapDownDetails details) {
          tapPos = details.globalPosition;
        },
        onLongPress: () {
          print('弹出会话菜单:${conversationItemData.title}');
        },
        child: ListTile(
          tileColor: selected ? Colors.blue[200] : Colors.transparent,
          leading: new Image.asset(
            conversationItemData.avatar,
            width: 40.0,
            height: 40.0,
            fit: BoxFit.cover,
          ),
          title: new Text(conversationItemData.title),
          subtitle: new Text(conversationItemData.des),
          trailing: new Text(conversationItemData.updateAt),
        ),
      ),
    );
  }
}
